﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nplJobsCommon.Common;
using System.Data;

namespace nplJobsDAL.Select
{
    public class SelectDivision : DataAccessBase
    {
        public SelectDivision()
        {
            StoredProcedureName = StoredProcedure.Name.spGetDivision.ToString();
        }

        #region GetCity
        public List<Division> GetDivision()
        {
            DataBaseHelper dbHelper;
            DataSet dsDivision;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dsDivision = dbHelper.Run(base.ConnectionString);
                return GetList(dsDivision);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region GetList
        private List<Division> GetList(DataSet dsDivision)
        {
            List<Division> locations;
            try
            {
                locations = (from n in dsDivision.Tables[0].AsEnumerable()
                             select new Division
                                {
                                    ID = n.Field<int>("ID"),
                                    Name = n.Field<string>("Name")
                                }).ToList();

                return locations;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion
    }
}
